package com.person.base.action;

import java.util.regex.Pattern;

import com.person.base.model.BaseUnit;
import com.person.base.model.BaseUser;
import com.person.base.service.BaseUnitService;
import com.person.base.service.BaseUserService;
import com.person.commons.struts2.BaseAction;

import org.apache.struts2.interceptor.validation.SkipValidation;
import org.springframework.orm.hibernate3.SpringSessionContext;

public class BaseUnitAction extends BaseAction {
	private BaseUnitService baseUnitService;
	private BaseUnit unit;
	private String unitId;
	private String unitName;
	private String unitTel;
	private String unitFax;
	private String unitPost;
	private String unitAddress;
	private String unitUrl;
	private String unitEmail;
	private String unitBank;
	private String unitBankNo;
	/**
	 * 显示单位管理界面
	 * 如果已存在单位，就显示单位信息，否则的话显示添加界面
	 */
	@SkipValidation
	public String index(){

		unit=baseUnitService.searchRecord();
		return "input";
	}
	
	/**
	 * 显示单位管理界面
	 * 如果已存在单位，就显示单位信息，否则的话显示添加界面
	 */
	public String execute(){
		
		char s=baseUnitService.unitModify(unit);
         if('1'==s)
        	 info="修改成功";
         else
        	 info="修改失败";
		return "success";
	}
	
	//验证execute方法
	public void validateExecute(){
		if(unit.getUnitName()==null ||"".equals(unit.getUnitName())){
			addFieldError("unit.unitName",getText("error.unitName"));
		}
//		if(unit.getUnitTel()!=null&&!"".equals(unit.getUnitTel())&&!Pattern.matches("\\d{3}-\\d{8}|\\d{4}-\\d{7}", unit.getUnitTel().trim())){
//			addFieldError("unit.unitTel",getText("error.unitTel"));
//		}
		if(unit.getUnitEmail()!=null &&!"".equals(unit.getUnitEmail())&&!Pattern.matches("^[\\w-]+(\\.[\\w-]+)*@[\\w-]+(\\.[\\w-]+)+$", unit.getUnitEmail().trim())){
			addFieldError("unit.unitEmail",getText("error.unitEmail"));
		}
	}
	public void setBaseUnitService(BaseUnitService baseUnitService) {
		this.baseUnitService = baseUnitService;
	}

	
	public BaseUnit getUnit() {
		return this.unit;
	}

	public void setUnit(BaseUnit unit) {
		this.unit = unit;
	}

	
	public String getUnitName() {
		return this.unitName;
	}

	public void setUnitName(String unitName) {
		this.unitName = unitName;
	}

	public String getUnitTel() {
		return this.unitTel;
	}

	public void setUnitTel(String unitTel) {
		this.unitTel = unitTel;
	}

	public String getUnitFax() {
		return this.unitFax;
	}

	public void setUnitFax(String unitFax) {
		this.unitFax = unitFax;
	}

	public String getUnitPost() {
		return this.unitPost;
	}

	public void setUnitPost(String unitPost) {
		this.unitPost = unitPost;
	}

	public String getUnitAddress() {
		return this.unitAddress;
	}

	public void setUnitAddress(String unitAddress) {
		this.unitAddress = unitAddress;
	}

	public String getUnitUrl() {
		return this.unitUrl;
	}

	public void setUnitUrl(String unitUrl) {
		this.unitUrl = unitUrl;
	}

	public String getUnitEmail() {
		return this.unitEmail;
	}

	public void setUnitEmail(String unitEmail) {
		this.unitEmail = unitEmail;
	}

	public String getUnitBank() {
		return this.unitBank;
	}

	public void setUnitBank(String unitBank) {
		this.unitBank = unitBank;
	}

	public String getUnitBankNo() {
		return this.unitBankNo;
	}

	public void setUnitBankNo(String unitBankNo) {
		this.unitBankNo = unitBankNo;
	}
}
